export default defineEventHandler(async (event) => {
  const { status, page = 1, pageSize = 10 } = getQuery(event)
  
  // 模拟订单数据
  const allOrders = [
    {
      id: '1',
      orderNo: 'ORD20250110001',
      userId: 'user1',
      items: [
        {
          id: 'item1',
          productId: '1',
          productTitle: 'Vue3 + Vite 后台管理系统',
          productCover: 'https://picsum.photos/seed/admin-system/600/400',
          price: 299,
          quantity: 1,
        },
      ],
      totalAmount: 299,
      status: 'paid' as const,
      paymentMethod: 'alipay' as const,
      createdAt: '2025-01-10 10:30:00',
      paidAt: '2025-01-10 10:35:00',
    },
    {
      id: '2',
      orderNo: 'ORD20250109002',
      userId: 'user1',
      items: [
        {
          id: 'item2',
          productId: '2',
          productTitle: 'React18 电商系统全栈项目',
          productCover: 'https://picsum.photos/seed/ecommerce/600/400',
          price: 499,
          quantity: 1,
        },
        {
          id: 'item3',
          productId: '3',
          productTitle: 'Nuxt3 内容管理系统',
          productCover: 'https://picsum.photos/seed/cms/600/400',
          price: 399,
          quantity: 1,
        },
      ],
      totalAmount: 898,
      status: 'pending' as const,
      paymentMethod: 'wechat' as const,
      createdAt: '2025-01-09 15:20:00',
    },
    {
      id: '3',
      orderNo: 'ORD20250108003',
      userId: 'user1',
      items: [
        {
          id: 'item4',
          productId: '4',
          productTitle: 'NestJS + TypeORM 企业级后端',
          productCover: 'https://picsum.photos/seed/backend/600/400',
          price: 599,
          quantity: 1,
        },
      ],
      totalAmount: 599,
      status: 'cancelled' as const,
      paymentMethod: 'alipay' as const,
      createdAt: '2025-01-08 09:15:00',
      cancelledAt: '2025-01-08 09:20:00',
    },
  ]
  
  // 根据状态筛选
  let filteredOrders = allOrders
  if (status && status !== 'all') {
    filteredOrders = allOrders.filter(order => order.status === status)
  }
  
  // 分页
  const pageNum = Number(page)
  const pageSizeNum = Number(pageSize)
  const start = (pageNum - 1) * pageSizeNum
  const end = start + pageSizeNum
  const items = filteredOrders.slice(start, end)
  
  return {
    code: 200,
    message: 'success',
    data: {
      items,
      pagination: {
        page: pageNum,
        pageSize: pageSizeNum,
        total: filteredOrders.length,
        totalPages: Math.ceil(filteredOrders.length / pageSizeNum),
      },
    },
  }
})
